using System.Collections.Generic;
using UnityEngine;

namespace FGUFW.Core.System
{
	public class AudioSystem : MonoBehaviour
	{
        List<AudioSource> _tempSourecs = new List<AudioSource>();

        public void Play(AudioClip clip)
        {
            var audioSource = _tempSourecs.Find(a=>
            {
                return !a.isPlaying;
            });

            if(!audioSource)
            {
                audioSource = gameObject.AddComponent<AudioSource>();
                _tempSourecs.Add(audioSource);
                audioSource.loop=false;
                audioSource.playOnAwake=false;
                audioSource.volume=0.5f;
            }
            audioSource.clip = clip;
            audioSource.Play();
        }
    }
}